package com.link.serve.tcp.handler.tactics.impl;

import com.link.serve.constants.ChannelAttrKey;
import com.link.serve.tcp.linkdata.SingleUserChannelManager;
import io.netty.channel.ChannelHandlerContext;
import io.netty.util.AttributeKey;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 登录心跳超时处理类 删除本机的心跳信息数据
 */
@Slf4j
@Component
public class LoginHeartbeatTimeoutHandler {

    public void handleTimeout(ChannelHandlerContext ctx) {
        AttributeKey<Long> attr = AttributeKey.valueOf(ChannelAttrKey.USER_ID);
        Long userId = ctx.channel().attr(attr).get();
        if (userId != null) {
            log.info("60s内未触发心跳包，进行断开用户{},该用户心跳总次数为{}",
                    userId,ctx.channel().attr(AttributeKey.valueOf(ChannelAttrKey.HEARTBEAT_TIMES)).get());
        }
    }
}